package edu.towson.greenteam.command;

import edu.towson.greenteam.InformationAggregator;
import edu.towson.greenteam.tab.Tab;
import edu.towson.greenteam.tab.TabAllItr;

public class CMDGetTab implements Command {
	InformationAggregator ia;
	int pinID;

	public CMDGetTab(InformationAggregator ia, int pinID) {
		this.ia = ia;
		this.pinID = pinID;
	}

	@Override
	public Object execute() {
		//find tab by ID
		TabAllItr tabAllItr = new TabAllItr(ia.getTabs());
		while (tabAllItr.hasNext())
		{
			Tab currentTab = tabAllItr.next();
			if (currentTab.getId() == pinID)
			{
				return currentTab;
			}
		}
		// otherwise return null		
		return null;
	}

}